from django.shortcuts import render
from django.template.defaultfilters import title
from books.models import BooksInfo

# Create your views here.

def booksView(request):
    title = '书籍列表'

    s = request.GET.get('s', '')
    t = request.GET.get('t', '')
    # readCount = BooksInfo.objects.order_by('readCount')
    # likes = BooksInfo.objects.order_by('likes')
    # rating = BooksInfo.objects.order_by('rating')

    if s:
        booklist = BooksInfo.objects.order_by('-' + s)
    if t:
        booklist = BooksInfo.objects.filter(types=t)
    return render(request, 'books.html', locals())

def detailView(request, id):
    # booklist = BooksInfo.objects.get()
    book = BooksInfo.objects.get(id=id)
    title = BooksInfo.objects.get(id=id).name
    img = BooksInfo.objects.get(id=id).img
    return render(request, 'details.html', locals())